Let's make a Teeny Tiny compiler
Let's make a teeny tiny compiler by cypherr.eth54 🥝 • 4y • 0 views • 0 clicks | |
AI summary of the linked articleAustin Z. Henley presents a tutorial for building a compiler in Python for Teeny Tiny, a BASIC-like teaching language that compiles to C, in about 500 lines of code. The language supports numerical variables, basic arithmetic, if statements, while loops, printing and input of numbers, labels and goto, and comments, but no functions, arrays, file I/O, or else. The compiler follows three steps: a lexer that breaks source code into tokens, a parser that checks token order, and an emitter that outputs C code. The post walks through writing the lexer, starting with a Lexer class in lex.py, character handling through nextChar and peek, and a TokenType enum for keywords and operators. The tutorial is the first of a three-part series, and the full source is in a GitHub repo. | |
Characters remaining: 10,000 comment guidelines | |
